#!/usr/bin/env bash
set -e

if ! [ -x "$(command -v javac)" ]; then
  echo 'Error: Java JDK (javac) is not installed.' >&2
  exit 2
fi

#
# nullUtil 1.0: JRE 6-7
# nullUtil 2.0: JRE 6-8
# nullUtil 3.0: JRE 8+
#
TARGET_VERSION=8

echo "[>---] Loading..."

FILES=$(find . -type f -name "*.java" -print)
FILE_COUNT=$(echo $FILES | wc -l)

echo "=> Removing any previous output.jar"

rm -fv output.jar

echo "=> Found $FILE_COUNT files to compile."
echo "[=>--] Compiling..."

mkdir -p ./build
javac -deprecation -d ./build -XDignore.symbol.file $FILES

echo "[==>-] Packaging..."

cd build
jar cvf ../output.jar *

echo "[===>] Cleaning up..."

rm -rfv ./build

echo "=> Compiled as output.jar."
exit 0
